﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;

namespace FinalProject
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                Utility.Init();
                InitPage();               
            }
            //string id = "3";
            //FinalProject.Help.ClassForTest clsTest = new FinalProject.Help.ClassForTest();
            //Utility.updateHoSo(clsTest.HoSo, id);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string idTinhThanh = "";
            idTinhThanh = Utility.GetIDRootObject(Utility.LstTinhThanh, ddlTinhThanh.SelectedItem.Text);
            string idChucVu = "";
            idChucVu = Utility.GetIDRootObject(Utility.LstChucVu, ddlChucDanh.SelectedItem.Text);
            string key = tbxInput.Text;

            if (idChucVu == "" && idTinhThanh == "" && key == "")
            {
                Response.Redirect("TimViecLam.aspx");
            }
            else
            {
                Utility.SearchCongViec(key, idTinhThanh, idChucVu);
                wucNganhNghe.Binding(0);

                if (Utility.LstCongViecCurrent != null && Utility.LstCongViecCurrent.Count > 0)
                {
                    Response.Redirect("TimViecLam.aspx?count=0");    
                }
                else
                {
                    Response.Redirect("TimViecLam.aspx?count=-1");
                }
            }
        }

        private void InitPage()
        {
            try
            {
                Utility.LoadDropDownList(ref ddlTinhThanh, Utility.LstTinhThanh);
                Utility.LoadDropDownList(ref ddlChucDanh, Utility.LstChucVu);
                //Binding(ref ddlTinhThanh, Utility.LstTinhThanh);                
                //Binding(ref ddlChucDanh, Utility.LstChucVu);
                wucNganhNghe.Binding(30);                
            }
            catch { }
        }

        private void Binding(ref DropDownList ddl, List<RootObject> lst)
        {
            ddl.DataSource = lst;
            ddl.DataValueField = "ID";
            ddl.DataTextField = "Ten";
            ddl.DataBind();           
        }

        protected void lbtXemThem_Click(object sender, EventArgs e)
        {
            Response.Redirect("TimViecLam.aspx");
        }
    }
}
